{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data = pd.read_table('train.txt' ,header=None, sep='\\t')\n",
    "valid_data = pd.read_table('valid.txt' ,header=None, sep='\\t')\n",
    "test_data = pd.read_table('test.txt' ,header=None, sep='\\t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(272115, 3)"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(17535, 3)"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "valid_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20466, 3)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [],
   "source": [
    "complete_data = pd.concat([train_data, valid_data, test_data], axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(310116, 3)"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "complete_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [],
   "source": [
    "tph_count = complete_data.groupby([0, 1]).count()\n",
    "tphr_count_sum = tph_count.groupby([1]).sum()\n",
    "tphr_count_count = tph_count.groupby([1]).count()\n",
    "tphr = tphr_count_sum / tphr_count_count\n",
    "tphr = tphr[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [],
   "source": [
    "hpt_count = complete_data.groupby([2, 1]).count()\n",
    "hptr_count_sum = hpt_count.groupby([1]).sum()\n",
    "hptr_count_count = hpt_count.groupby([1]).count()\n",
    "hptr = hptr_count_sum / hptr_count_count\n",
    "hptr = hptr[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/base/aareas/schema/administrative_area/capital is 1-1 relation\n",
      "\n",
      "/base/popstra/celebrity/breakup./base/popstra/breakup/participant is 1-1 relation\n",
      "\n",
      "/celebrities/celebrity/sexual_relationships./celebrities/romantic_relationship/celebrity is 1-1 relation\n",
      "\n",
      "/dataworld/gardening_hint/split_to is 1-1 relation\n",
      "\n",
      "/education/educational_institution/campuses is 1-1 relation\n",
      "\n",
      "/education/educational_institution_campus/educational_institution is 1-1 relation\n",
      "\n",
      "/film/film/prequel is 1-1 relation\n",
      "\n",
      "/influence/influence_node/peers./influence/peer_relationship/peers is 1-1 relation\n",
      "\n",
      "/location/capital_of_administrative_division/capital_of./location/administrative_division_capital_relationship/administrative_division is 1-1 relation\n",
      "\n",
      "/location/country/capital is 1-1 relation\n",
      "\n",
      "/location/hud_county_place/place is 1-1 relation\n",
      "\n",
      "/location/us_county/county_seat is 1-1 relation\n",
      "\n",
      "/organization/organization_founder/organizations_founded is 1-1 relation\n",
      "\n",
      "/people/person/sibling_s./people/sibling_relationship/sibling is 1-1 relation\n",
      "\n",
      "/people/person/spouse_s./people/marriage/spouse is 1-1 relation\n",
      "\n",
      "/sports/sports_team_location/teams is 1-1 relation\n",
      "\n",
      "/tv/tv_program/program_creator is 1-1 relation\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# print 1-1 data\n",
    "for index in hptr.index:\n",
    "    if hptr.loc[index] < 1.5 and tphr.loc[index] < 1.5:\n",
    "        print(\"{} is 1-1 relation\\n\".format(index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/award/hall_of_fame/inductees./award/hall_of_fame_induction/inductee is 1-n relation\n",
      "\n",
      "/base/americancomedy/celebrity_impressionist/celebrities_impersonated is 1-n relation\n",
      "\n",
      "/base/locations/continents/countries_within is 1-n relation\n",
      "\n",
      "/broadcast/content/artist is 1-n relation\n",
      "\n",
      "/education/educational_degree/people_with_this_degree./education/education/student is 1-n relation\n",
      "\n",
      "/education/educational_institution/students_graduates./education/education/student is 1-n relation\n",
      "\n",
      "/education/field_of_study/students_majoring./education/education/student is 1-n relation\n",
      "\n",
      "/film/director/film is 1-n relation\n",
      "\n",
      "/film/film/personal_appearances./film/personal_film_appearance/person is 1-n relation\n",
      "\n",
      "/film/film_set_designer/film_sets_designed is 1-n relation\n",
      "\n",
      "/film/film_subject/films is 1-n relation\n",
      "\n",
      "/film/special_film_performance_type/film_performance_type./film/performance/film is 1-n relation\n",
      "\n",
      "/government/political_party/politicians_in_this_party./government/political_party_tenure/politician is 1-n relation\n",
      "\n",
      "/location/country/second_level_divisions is 1-n relation\n",
      "\n",
      "/medicine/disease/notable_people_with_this_condition is 1-n relation\n",
      "\n",
      "/organization/organization/child./organization/organization_relationship/child is 1-n relation\n",
      "\n",
      "/organization/role/leaders./organization/leadership/organization is 1-n relation\n",
      "\n",
      "/people/cause_of_death/people is 1-n relation\n",
      "\n",
      "/people/ethnicity/people is 1-n relation\n",
      "\n",
      "/people/marriage_union_type/unions_of_this_type./people/marriage/location_of_ceremony is 1-n relation\n",
      "\n",
      "/sports/sport/pro_athletes./sports/pro_sports_played/athlete is 1-n relation\n",
      "\n",
      "/sports/sports_league/teams./sports/sports_league_participation/team is 1-n relation\n",
      "\n",
      "/tv/non_character_role/tv_regular_personal_appearances./tv/tv_regular_personal_appearance/person is 1-n relation\n",
      "\n",
      "/tv/tv_network/programs./tv/tv_network_duration/program is 1-n relation\n",
      "\n",
      "/tv/tv_program/regular_cast./tv/regular_tv_appearance/actor is 1-n relation\n",
      "\n",
      "/user/ktrueman/default_domain/international_organization/member_states is 1-n relation\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# print 1-n data\n",
    "for index in hptr.index:\n",
    "    if hptr.loc[index] < 1.5 and tphr.loc[index] >= 1.5:\n",
    "        print(\"{} is 1-n relation\\n\".format(index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/award/award_category/category_of is n-1 relation\n",
      "\n",
      "/award/ranked_item/appears_in_ranked_lists./award/ranking/list is n-1 relation\n",
      "\n",
      "/base/aareas/schema/administrative_area/administrative_area_type is n-1 relation\n",
      "\n",
      "/base/aareas/schema/administrative_area/administrative_parent is n-1 relation\n",
      "\n",
      "/base/biblioness/bibs_location/country is n-1 relation\n",
      "\n",
      "/base/biblioness/bibs_location/state is n-1 relation\n",
      "\n",
      "/base/eating/practicer_of_diet/diet is n-1 relation\n",
      "\n",
      "/base/schemastaging/organization_extra/phone_number./base/schemastaging/phone_sandbox/contact_category is n-1 relation\n",
      "\n",
      "/base/schemastaging/person_extra/net_worth./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/business/business_operation/assets./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/business/business_operation/operating_income./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/business/business_operation/revenue./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/common/topic/webpage./common/webpage/category is n-1 relation\n",
      "\n",
      "/education/educational_institution/school_type is n-1 relation\n",
      "\n",
      "/education/university/domestic_tuition./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/education/university/fraternities_and_sororities is n-1 relation\n",
      "\n",
      "/education/university/international_tuition./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/education/university/local_tuition./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/film/actor/dubbing_performances./film/dubbing_performance/language is n-1 relation\n",
      "\n",
      "/film/actor/film./film/performance/special_performance_type is n-1 relation\n",
      "\n",
      "/film/film/cinematography is n-1 relation\n",
      "\n",
      "/film/film/costume_design_by is n-1 relation\n",
      "\n",
      "/film/film/distributors./film/film_film_distributor_relationship/region is n-1 relation\n",
      "\n",
      "/film/film/edited_by is n-1 relation\n",
      "\n",
      "/film/film/estimated_budget./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/film/film/executive_produced_by is n-1 relation\n",
      "\n",
      "/film/film/film_art_direction_by is n-1 relation\n",
      "\n",
      "/film/film/film_festivals is n-1 relation\n",
      "\n",
      "/film/film/film_format is n-1 relation\n",
      "\n",
      "/film/film/film_production_design_by is n-1 relation\n",
      "\n",
      "/film/film/music is n-1 relation\n",
      "\n",
      "/film/film/other_crew./film/film_crew_gig/crewmember is n-1 relation\n",
      "\n",
      "/film/film/produced_by is n-1 relation\n",
      "\n",
      "/film/film/production_companies is n-1 relation\n",
      "\n",
      "/film/film/release_date_s./film/film_regional_release_date/film_regional_debut_venue is n-1 relation\n",
      "\n",
      "/film/film/release_date_s./film/film_regional_release_date/film_release_distribution_medium is n-1 relation\n",
      "\n",
      "/film/film/runtime./film/film_cut/film_release_region is n-1 relation\n",
      "\n",
      "/film/film/story_by is n-1 relation\n",
      "\n",
      "/film/film/written_by is n-1 relation\n",
      "\n",
      "/film/person_or_entity_appearing_in_film/films./film/personal_film_appearance/type_of_appearance is n-1 relation\n",
      "\n",
      "/government/politician/government_positions_held./government/government_position_held/jurisdiction_of_office is n-1 relation\n",
      "\n",
      "/location/administrative_division/country is n-1 relation\n",
      "\n",
      "/location/administrative_division/first_level_division_of is n-1 relation\n",
      "\n",
      "/location/country/official_language is n-1 relation\n",
      "\n",
      "/location/hud_county_place/county is n-1 relation\n",
      "\n",
      "/location/hud_foreclosure_area/estimated_number_of_mortgages./measurement_unit/dated_integer/source is n-1 relation\n",
      "\n",
      "/location/location/time_zones is n-1 relation\n",
      "\n",
      "/location/statistical_region/gdp_nominal./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/location/statistical_region/gdp_nominal_per_capita./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/location/statistical_region/gdp_real./measurement_unit/adjusted_money_value/adjustment_currency is n-1 relation\n",
      "\n",
      "/location/statistical_region/gni_per_capita_in_ppp_dollars./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/location/statistical_region/rent50_2./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/music/artist/origin is n-1 relation\n",
      "\n",
      "/music/group_member/membership./music/group_membership/group is n-1 relation\n",
      "\n",
      "/music/instrument/family is n-1 relation\n",
      "\n",
      "/organization/endowed_organization/endowment./measurement_unit/dated_money_value/currency is n-1 relation\n",
      "\n",
      "/organization/non_profit_organization/registered_with./organization/non_profit_registration/registering_agency is n-1 relation\n",
      "\n",
      "/organization/organization/headquarters./location/mailing_address/citytown is n-1 relation\n",
      "\n",
      "/organization/organization/headquarters./location/mailing_address/country is n-1 relation\n",
      "\n",
      "/organization/organization/headquarters./location/mailing_address/state_province_region is n-1 relation\n",
      "\n",
      "/organization/organization/place_founded is n-1 relation\n",
      "\n",
      "/people/deceased_person/place_of_burial is n-1 relation\n",
      "\n",
      "/people/deceased_person/place_of_death is n-1 relation\n",
      "\n",
      "/people/person/employment_history./business/employment_tenure/company is n-1 relation\n",
      "\n",
      "/people/person/gender is n-1 relation\n",
      "\n",
      "/people/person/languages is n-1 relation\n",
      "\n",
      "/people/person/nationality is n-1 relation\n",
      "\n",
      "/people/person/place_of_birth is n-1 relation\n",
      "\n",
      "/people/person/religion is n-1 relation\n",
      "\n",
      "/people/person/spouse_s./people/marriage/location_of_ceremony is n-1 relation\n",
      "\n",
      "/people/person/spouse_s./people/marriage/type_of_union is n-1 relation\n",
      "\n",
      "/people/profession/specialization_of is n-1 relation\n",
      "\n",
      "/sports/sports_team/sport is n-1 relation\n",
      "\n",
      "/time/event/instance_of_recurring_event is n-1 relation\n",
      "\n",
      "/tv/tv_personality/tv_regular_appearances./tv/tv_regular_personal_appearance/program is n-1 relation\n",
      "\n",
      "/tv/tv_producer/programs_produced./tv/tv_producer_term/producer_type is n-1 relation\n",
      "\n",
      "/tv/tv_program/country_of_origin is n-1 relation\n",
      "\n",
      "/tv/tv_program/languages is n-1 relation\n",
      "\n",
      "/tv/tv_program/tv_producer./tv/tv_producer_term/producer_type is n-1 relation\n",
      "\n",
      "/tv/tv_writer/tv_programs./tv/tv_program_writer_relationship/tv_program is n-1 relation\n",
      "\n",
      "/user/tsegaran/random/taxonomy_subject/entry./user/tsegaran/random/taxonomy_entry/taxonomy is n-1 relation\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# print n-1 data\n",
    "for index in hptr.index:\n",
    "    if hptr.loc[index] >= 1.5 and tphr.loc[index] < 1.5:\n",
    "        print('{} is n-1 relation\\n'.format(index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/american_football/football_team/current_roster./sports/sports_team_roster/position is n-n relation\n",
      "\n",
      "/award/award_category/disciplines_or_subjects is n-n relation\n",
      "\n",
      "/award/award_category/nominees./award/award_nomination/nominated_for is n-n relation\n",
      "\n",
      "/award/award_category/winners./award/award_honor/award_winner is n-n relation\n",
      "\n",
      "/award/award_category/winners./award/award_honor/ceremony is n-n relation\n",
      "\n",
      "/award/award_ceremony/awards_presented./award/award_honor/award_winner is n-n relation\n",
      "\n",
      "/award/award_ceremony/awards_presented./award/award_honor/honored_for is n-n relation\n",
      "\n",
      "/award/award_nominated_work/award_nominations./award/award_nomination/nominated_for is n-n relation\n",
      "\n",
      "/award/award_nominee/award_nominations./award/award_nomination/award is n-n relation\n",
      "\n",
      "/award/award_nominee/award_nominations./award/award_nomination/award_nominee is n-n relation\n",
      "\n",
      "/award/award_nominee/award_nominations./award/award_nomination/nominated_for is n-n relation\n",
      "\n",
      "/award/award_winner/awards_won./award/award_honor/award_winner is n-n relation\n",
      "\n",
      "/award/award_winning_work/awards_won./award/award_honor/award is n-n relation\n",
      "\n",
      "/award/award_winning_work/awards_won./award/award_honor/award_winner is n-n relation\n",
      "\n",
      "/award/award_winning_work/awards_won./award/award_honor/honored_for is n-n relation\n",
      "\n",
      "/base/culturalevent/event/entity_involved is n-n relation\n",
      "\n",
      "/base/localfood/seasonal_month/produce_available./base/localfood/produce_availability/seasonal_months is n-n relation\n",
      "\n",
      "/base/marchmadness/ncaa_basketball_tournament/seeds./base/marchmadness/ncaa_tournament_seed/team is n-n relation\n",
      "\n",
      "/base/petbreeds/city_with_dogs/top_breeds./base/petbreeds/dog_city_relationship/dog_breed is n-n relation\n",
      "\n",
      "/base/popstra/celebrity/canoodled./base/popstra/canoodled/participant is n-n relation\n",
      "\n",
      "/base/popstra/celebrity/dated./base/popstra/dated/participant is n-n relation\n",
      "\n",
      "/base/popstra/celebrity/friendship./base/popstra/friendship/participant is n-n relation\n",
      "\n",
      "/base/popstra/location/vacationers./base/popstra/vacation_choice/vacationer is n-n relation\n",
      "\n",
      "/base/saturdaynightlive/snl_cast_member/seasons./base/saturdaynightlive/snl_season_tenure/cast_members is n-n relation\n",
      "\n",
      "/base/schemastaging/organization_extra/phone_number./base/schemastaging/phone_sandbox/service_language is n-n relation\n",
      "\n",
      "/base/schemastaging/organization_extra/phone_number./base/schemastaging/phone_sandbox/service_location is n-n relation\n",
      "\n",
      "/base/x2010fifaworldcupsouthafrica/world_cup_squad/current_world_cup_squad./base/x2010fifaworldcupsouthafrica/current_world_cup_squad/current_club is n-n relation\n",
      "\n",
      "/baseball/baseball_team/team_stats./baseball/baseball_team_stats/season is n-n relation\n",
      "\n",
      "/business/business_operation/industry is n-n relation\n",
      "\n",
      "/business/job_title/people_with_this_title./business/employment_tenure/company is n-n relation\n",
      "\n",
      "/celebrities/celebrity/celebrity_friends./celebrities/friendship/friend is n-n relation\n",
      "\n",
      "/education/educational_degree/people_with_this_degree./education/education/institution is n-n relation\n",
      "\n",
      "/education/educational_degree/people_with_this_degree./education/education/major_field_of_study is n-n relation\n",
      "\n",
      "/education/educational_institution/colors is n-n relation\n",
      "\n",
      "/education/educational_institution/students_graduates./education/education/major_field_of_study is n-n relation\n",
      "\n",
      "/education/field_of_study/students_majoring./education/education/major_field_of_study is n-n relation\n",
      "\n",
      "/film/actor/film./film/performance/film is n-n relation\n",
      "\n",
      "/film/film/country is n-n relation\n",
      "\n",
      "/film/film/distributors./film/film_film_distributor_relationship/film_distribution_medium is n-n relation\n",
      "\n",
      "/film/film/dubbing_performances./film/dubbing_performance/actor is n-n relation\n",
      "\n",
      "/film/film/featured_film_locations is n-n relation\n",
      "\n",
      "/film/film/genre is n-n relation\n",
      "\n",
      "/film/film/language is n-n relation\n",
      "\n",
      "/film/film/other_crew./film/film_crew_gig/film_crew_role is n-n relation\n",
      "\n",
      "/film/film/release_date_s./film/film_regional_release_date/film_release_region is n-n relation\n",
      "\n",
      "/film/film_distributor/films_distributed./film/film_film_distributor_relationship/film is n-n relation\n",
      "\n",
      "/food/food/nutrients./food/nutrition_fact/nutrient is n-n relation\n",
      "\n",
      "/government/government_office_category/officeholders./government/government_position_held/jurisdiction_of_office is n-n relation\n",
      "\n",
      "/government/governmental_body/members./government/government_position_held/legislative_sessions is n-n relation\n",
      "\n",
      "/government/legislative_session/members./government/government_position_held/district_represented is n-n relation\n",
      "\n",
      "/government/legislative_session/members./government/government_position_held/legislative_sessions is n-n relation\n",
      "\n",
      "/government/politician/government_positions_held./government/government_position_held/basic_title is n-n relation\n",
      "\n",
      "/government/politician/government_positions_held./government/government_position_held/legislative_sessions is n-n relation\n",
      "\n",
      "/ice_hockey/hockey_team/current_roster./sports/sports_team_roster/position is n-n relation\n",
      "\n",
      "/influence/influence_node/influenced_by is n-n relation\n",
      "\n",
      "/language/human_language/countries_spoken_in is n-n relation\n",
      "\n",
      "/location/country/form_of_government is n-n relation\n",
      "\n",
      "/location/location/adjoin_s./location/adjoining_relationship/adjoins is n-n relation\n",
      "\n",
      "/location/location/contains is n-n relation\n",
      "\n",
      "/location/location/partially_contains is n-n relation\n",
      "\n",
      "/location/statistical_region/places_exported_to./location/imports_and_exports/exported_to is n-n relation\n",
      "\n",
      "/location/statistical_region/religions./location/religion_percentage/religion is n-n relation\n",
      "\n",
      "/media_common/netflix_genre/titles is n-n relation\n",
      "\n",
      "/medicine/disease/risk_factors is n-n relation\n",
      "\n",
      "/medicine/symptom/symptom_of is n-n relation\n",
      "\n",
      "/military/military_combatant/military_conflicts./military/military_combatant_group/combatants is n-n relation\n",
      "\n",
      "/military/military_conflict/combatants./military/military_combatant_group/combatants is n-n relation\n",
      "\n",
      "/music/artist/contribution./music/recording_contribution/performance_role is n-n relation\n",
      "\n",
      "/music/artist/track_contributions./music/track_contribution/role is n-n relation\n",
      "\n",
      "/music/genre/artists is n-n relation\n",
      "\n",
      "/music/genre/parent_genre is n-n relation\n",
      "\n",
      "/music/group_member/membership./music/group_membership/role is n-n relation\n",
      "\n",
      "/music/instrument/instrumentalists is n-n relation\n",
      "\n",
      "/music/performance_role/guest_performances./music/recording_contribution/performance_role is n-n relation\n",
      "\n",
      "/music/performance_role/regular_performances./music/group_membership/group is n-n relation\n",
      "\n",
      "/music/performance_role/regular_performances./music/group_membership/role is n-n relation\n",
      "\n",
      "/music/performance_role/track_performances./music/track_contribution/role is n-n relation\n",
      "\n",
      "/music/record_label/artist is n-n relation\n",
      "\n",
      "/olympics/olympic_games/medals_awarded./olympics/olympic_medal_honor/medal is n-n relation\n",
      "\n",
      "/olympics/olympic_games/participating_countries is n-n relation\n",
      "\n",
      "/olympics/olympic_games/sports is n-n relation\n",
      "\n",
      "/olympics/olympic_participating_country/athletes./olympics/olympic_athlete_affiliation/olympics is n-n relation\n",
      "\n",
      "/olympics/olympic_participating_country/medals_won./olympics/olympic_medal_honor/medal is n-n relation\n",
      "\n",
      "/olympics/olympic_participating_country/medals_won./olympics/olympic_medal_honor/olympics is n-n relation\n",
      "\n",
      "/olympics/olympic_sport/athletes./olympics/olympic_athlete_affiliation/country is n-n relation\n",
      "\n",
      "/olympics/olympic_sport/athletes./olympics/olympic_athlete_affiliation/olympics is n-n relation\n",
      "\n",
      "/organization/organization_member/member_of./organization/organization_membership/organization is n-n relation\n",
      "\n",
      "/people/ethnicity/geographic_distribution is n-n relation\n",
      "\n",
      "/people/ethnicity/languages_spoken is n-n relation\n",
      "\n",
      "/people/person/places_lived./people/place_lived/location is n-n relation\n",
      "\n",
      "/people/person/profession is n-n relation\n",
      "\n",
      "/soccer/football_player/current_team./sports/sports_team_roster/team is n-n relation\n",
      "\n",
      "/soccer/football_team/current_roster./soccer/football_roster_position/position is n-n relation\n",
      "\n",
      "/soccer/football_team/current_roster./sports/sports_team_roster/position is n-n relation\n",
      "\n",
      "/sports/pro_athlete/teams./sports/sports_team_roster/team is n-n relation\n",
      "\n",
      "/sports/professional_sports_team/draft_picks./sports/sports_league_draft_pick/draft is n-n relation\n",
      "\n",
      "/sports/professional_sports_team/draft_picks./sports/sports_league_draft_pick/school is n-n relation\n",
      "\n",
      "/sports/sports_league_draft/picks./sports/sports_league_draft_pick/school is n-n relation\n",
      "\n",
      "/sports/sports_position/players./american_football/football_historical_roster_position/position_s is n-n relation\n",
      "\n",
      "/sports/sports_position/players./sports/sports_team_roster/position is n-n relation\n",
      "\n",
      "/sports/sports_position/players./sports/sports_team_roster/team is n-n relation\n",
      "\n",
      "/sports/sports_team/colors is n-n relation\n",
      "\n",
      "/sports/sports_team/roster./american_football/football_historical_roster_position/position_s is n-n relation\n",
      "\n",
      "/sports/sports_team/roster./american_football/football_roster_position/position is n-n relation\n",
      "\n",
      "/sports/sports_team/roster./baseball/baseball_roster_position/position is n-n relation\n",
      "\n",
      "/sports/sports_team/roster./basketball/basketball_roster_position/position is n-n relation\n",
      "\n",
      "/time/event/locations is n-n relation\n",
      "\n",
      "/travel/travel_destination/climate./travel/travel_destination_monthly_climate/month is n-n relation\n",
      "\n",
      "/travel/travel_destination/how_to_get_here./travel/transportation/mode_of_transportation is n-n relation\n",
      "\n",
      "/tv/tv_producer/programs_produced./tv/tv_producer_term/program is n-n relation\n",
      "\n",
      "/tv/tv_program/genre is n-n relation\n",
      "\n",
      "/user/alexander/philosophy/philosopher/interests is n-n relation\n",
      "\n",
      "/user/jg/default_domain/olympic_games/sports is n-n relation\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# print n-n data\n",
    "for index in hptr.index:\n",
    "    if hptr.loc[index] >= 1.5 and tphr.loc[index] >= 1.5:\n",
    "        print(\"{} is n-n relation\\n\".format(index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 281,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data1_1, test_data1_n, test_datan_1, test_datan_n = None, None, None, None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 282,
   "metadata": {},
   "outputs": [],
   "source": [
    "def add_rel_category(rel_category, new_data):\n",
    "    if rel_category is not None:\n",
    "        return rel_category.append(row)\n",
    "    else:\n",
    "        return pd.DataFrame(data=np.array([row.to_numpy()]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 283,
   "metadata": {},
   "outputs": [],
   "source": [
    "for index, row in test_data.iterrows():\n",
    "    rel = row[1]\n",
    "    hptr_temp = hptr.loc[rel]\n",
    "    tphr_temp = tphr.loc[rel]\n",
    "    if hptr_temp < 1.5 and tphr_temp < 1.5:\n",
    "        test_data1_1 = add_rel_category(test_data1_1, row)\n",
    "    elif hptr_temp < 1.5 and tphr_temp >= 1.5:\n",
    "        test_data1_n = add_rel_category(test_data1_n, row)\n",
    "    elif hptr_temp >= 1.5 and tphr_temp < 1.5:\n",
    "        test_datan_1 = add_rel_category(test_datan_1, row)\n",
    "    elif hptr_temp >= 1.5 and tphr_temp >= 1.5:\n",
    "        test_datan_n = add_rel_category(test_datan_n, row)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 284,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4185, 3)"
      ]
     },
     "execution_count": 284,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_datan_1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data1_1.to_csv('1-1.txt', sep='\\t', header=None, index=None)\n",
    "test_data1_n.to_csv('1-n.txt', sep='\\t', header=None, index=None)\n",
    "test_datan_1.to_csv('n-1.txt', sep='\\t', header=None, index=None)\n",
    "test_datan_n.to_csv('n-n.txt', sep='\\t', header=None, index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:jupyter] *",
   "language": "python",
   "name": "conda-env-jupyter-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
